//
//  ValutViewController.m
//  ForeverLove
//
//  Created by 王维斌 on 15/11/17.
//  Copyright © 2015年 文萱竹. All rights reserved.
//

#import "ValutViewController.h"

@interface ValutViewController ()<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>

- (IBAction)peopleButtonClick:(UIButton *)sender;

@property (strong, nonatomic) IBOutlet UIButton *button;

@end

@implementation ValutViewController

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)peopleButtonClick:(UIButton *)sender {
    UIAlertController *al = [UIAlertController alertControllerWithTitle:nil message:@"选取照片" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"拍摄照片" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [self setImagePickerController:UIImagePickerControllerSourceTypeCamera];
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"从相册中选" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
         [self setImagePickerController:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
    }];
    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSLog(@"好的");
    }];
    [al addAction:action1];
    [al addAction:action2];
    [al addAction:action3];
    
    [self presentViewController:al animated:YES completion:nil];
}
- (void)setImagePickerController:(UIImagePickerControllerSourceType)soure
{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = soure;
    
    
    [imagePicker setEditing:YES];
    imagePicker.allowsEditing = YES;
    
    // 模态推出视图
    [self presentViewController:imagePicker animated:YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    [self.button setImage:image forState:UIControlStateNormal];
    
    [picker dismissViewControllerAnimated:YES completion:nil];
}


@end
